package Thread;

/**
 * 静态方法上如果使用了synchronized，那么该方法一定具有同步效果。
 *
 * 演示git
 */
public class SyncDemo3 {
    public static void main(String[] args) {
        Thread t1 = new Thread(){
            @Override
            public void run() {
                Foo.doSome();
            }
        };

        Thread t2 = new Thread(){
            @Override
            public void run() {
                Foo.doSome();
            }
        };

        t1.start();
        t2.start();
    }

}

class Foo{
    //public synchronized static void doSome(){
    public static void doSome(){
        synchronized (Foo.class){
            try {
                Thread t = Thread.currentThread();
                System.out.println(t.getName()+":正在执行dosome方法");
                Thread.sleep(5000);
                System.out.println(t.getName()+":执行完毕");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}